﻿<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <title>Welcome to @ViewBag.Title </title>
        <link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />
        <meta name="viewport" content="width=device-width" />
        @Styles.Render("~/Content/css") 
        @Scripts.Render("~/bundles/jquery")
        @Scripts.Render("~/bundles/modernizr")
        @Scripts.Render("~/bundles/knockout")
        @Scripts.Render("~/bundles/liveSDK")
        @Scripts.Render("~/bundles/jstree")
        
         <script type= "text/javascript">
             $(document).ready(function () {
                 Refresh();
                 NodeSelect();
             });

             function Refresh() {
                 $('#MainTree').jstree({
                     "json_data": {
                         "ajax": {
                             "url": "/Dropbox/GetDropboxTreeData",
                             "type": "POST",
                             "async": "true",
                             "dataType": "json",
                             "contentType": "application/json charset=utf-8"
                         }
                     },

                     "plugins": ["themes", "json_data", "dnd", "contextmenu", "types", "ui", "crrm"]

                 });
             }

              function NodeSelect() {
                  $("#MainTree").bind("select_node.jstree", function (event, data) {
                      var nodeRoot = $.jstree._focused().get_selected();
                      var nodePath = data.rslt.obj.attr("path");
                      var p_NodeFullPath = data.inst._get_parent(data.rslt.obj).attr("id");
                      alert("Selected node route = " + nodeRoot);
                      alert("Selected node path = " + nodePath)
                  });
              }

             $("#MainTree").jstree("set_theme", "apple")
             $('#MainTree').jstree('get_selected').attr('id')

             $('#MainTree').bind("move_node.jstree", function (e, data) {
                 data.rslt.o.each(function (i) {
                     $.ajax({
                         async: false,
                         type: 'POST',
                         url: "/Dropbox/MoveData",
                         data: {
                             "path": $(this).attr("id"),
                             "destination": data.rslt.np.attr("id")
                         },
                         success: function (r) {
                             Refresh();
                         }
                     });
                 });
             });

             $('#MainTree').bind("create.jstree", function (e, data) {
                 $.post(
				        "/Home/CreateFolder",
				        {
				            "path": data.rslt.parent.attr("id"),
				            "newname": data.rslt.name
				        },
				        function (r) {
				            Refresh();
				        }
			        );
             });
                </script>
        @RenderSection("scripts", required: false)

    </head>
    <body>
        <header>
            <div class="content-wrapper">
                <div class="float-left">
                    <p class="site-title">@Html.ActionLink("CloudTree", "Index", "Home")</p>
                </div>
                <div class="float-right">
                    <section id="login">
                        @Html.Partial("_LoginPartial")
                    </section>
                    <nav>
                        <ul id="menu">
                            <li>@Html.ActionLink("Home", "Index", "Home")</li>
                            <li>@Html.ActionLink("About", "About", "Home")</li>
                            <li>@Html.ActionLink("Contact", "Contact", "Home")</li>
                        </ul>
                    </nav>
                </div>
            </div>
        </header>
      
    <div class="container-narrow">
        <div class="masthead">
            <ul class="nav nav-pills pull-right">
                
            </ul>
            <h3 class="muted">@ViewBag.Title</h3>
        </div>
        <div id="body" class="container">
            @RenderSection("featured", required: false)
            <section>
                @RenderBody()
            </section>
        </div>

        <hr />
        <div id="footer">
            <div class="container">
                <p class="muted credit">&copy; @DateTime.Now.Year Designed & Developed by Ciaràn Rice</p>
            </div>
        </div>
    </div>

    </body>
</html>